package com.tzb.restorder.controller;

import com.tzb.restorder.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;



@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    /**
     *
     * @param id
     * @return
     */
   // @SentinelResource(value = "orderFindById",blockHandler = " orderBlockHandler",fallback = "orderFallback")
    @GetMapping("/buy/{id}")
    public Product findById(@PathVariable Long id){

        if(id !=1L){
            throw new RuntimeException("错误");
        }

        return restTemplate.getForObject("http://service-product/product/1", Product.class);
    }

//    /**
//     * 定义降级逻辑
//     * @param id
//     * @return
//     */
//    public Product orderBlockHandler(Long id){
//        Product product = new Product();
//        product.setProductName("触发熔断的降级方法");
//        return product;
//    }
//
//    public Product orderFallback(Long id){
//        Product product = new Product();
//        product.setProductName("抛出异常执行的降级方法");
//        return product;
//    }

}
